package org.xserver.component.redis.spring;

import java.util.HashMap;
import java.util.Map;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;


public class RedisTest {

	public static void main(String[] agrs) {

		 /*Set<HostAndPort> jedisNodes = new HashSet<HostAndPort>();
		 jedisNodes.add(new HostAndPort("192.168.48.129",6382));
		 JedisCluster jc = new JedisCluster(jedisNodes);
		 jc.set("qq","12312221111sadas1");
		 String value = jc.get("qq");
		 System.out.println(value);*/
		
		/*JedisPoolConfig config = new JedisPoolConfig();  
        config.setMaxTotal(20);  
        config.setMaxIdle(2); 
        
        
        HostAndPort hp0 = new HostAndPort("192.168.48.129", 6379);  
        HostAndPort hp1 = new HostAndPort("192.168.48.129", 6381);  
        HostAndPort hp2 = new HostAndPort("192.168.48.129", 6382);  
        HostAndPort hp3 = new HostAndPort("192.168.48.129", 6479);  
        HostAndPort hp4 = new HostAndPort("192.168.48.129", 6481);  
        HostAndPort hp5 = new HostAndPort("192.168.48.129", 6482);  
  
        Set<HostAndPort> hps = new HashSet<HostAndPort>();  
        hps.add(hp0);  
        hps.add(hp1);  
        hps.add(hp2);  
        hps.add(hp3);  
        hps.add(hp4);  
        hps.add(hp5);  
  
        // 超时，最大的转发数，最大链接数，最小链接数都会影响到集群  
        JedisCluster jedisCluster = new JedisCluster(hps, 5000, 10, config); 
       
        
        Map<String, JedisPool> map = jedisCluster.getClusterNodes();*/
       
        
        
        /*long start = System.currentTimeMillis();  
        for (int i = 0; i < 10000; i++) {  
            jedisCluster.set("sn" + i, "n" + i);  
        }
		
        long end = System.currentTimeMillis();  
        System.out.println(start);
        System.out.println(end);
        System.out.println("Simple  @ Sharding Set : " + (end - start));  
        
        for (int i = 0; i < 10000; i++) {  
            System.out.println(jedisCluster.get("sn" + i));  
        } 
  
        jedisCluster.close();*/
        
        /*
        JedisPool jedisPool = new JedisPool(config,"192.168.48.129",6479);
        Jedis jedis = jedisPool.getResource(); 
        
        jedis.set("hmj", "hello world");
        jedis.set("sn9925","hmj");
        String key = jedis.get("hmj");
        String key2 = jedis.get("sn9925");
        
		System.out.println(key+"   "+key2);
        
        
		Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6380));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6381));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6382));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6383));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6384));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7380));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7381));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7382));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7383));  
        jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7384));  */
        
        
        
        /*List<JedisShardInfo> shards = Arrays.asList(
                new JedisShardInfo("192.168.48.129",6379),
                new JedisShardInfo("192.168.48.129",6381),
                new JedisShardInfo("192.168.48.129",6382),
                new JedisShardInfo("192.168.48.129",6479),
                new JedisShardInfo("192.168.48.129",6481),
                new JedisShardInfo("192.168.48.129",6482));
        
        ShardedJedisPool pool = new ShardedJedisPool(config, shards);
        ShardedJedis one =  pool.getResource();
        Jedis jedis = one.getShard("sn1");
        
        String ss = jedis.get("sn1");
        System.out.println(ss);*/
       
		
		JedisPool jedisPool = new JedisPool(new JedisPoolConfig(),"192.168.48.129",6379);
        Jedis jedis = jedisPool.getResource(); 
        Map map = new HashMap();
        map.put("name", "hmj11");
        map.put("age", "262");
        map.put("sex","男");
        jedis.hmset("hmj",map);
        Map<String,String> result = jedis.hgetAll("hmj");
        jedisPool.returnResource(jedis);
        
        //jedis.set("hmj", "hello world");
        /*jedis.watch("hmj");
        jedis.watch("aa");
        Transaction tx = jedis.multi();
        tx.set("hmj", "12312asa");
        tx.set("aa", "123");
        List<Object> list = tx.exec();
        for(Object ss:list){
        	System.out.println(String.valueOf(ss)+"   "+String.valueOf(ss).equals("OK"));
        }
        jedis.disconnect();
        jedisPool.returnResource(jedis);*/
		//System.out.println(key==null);
		
	}
}
